package cc.ufinity.networkdiagnose.widget;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import cc.ufinity.networkdiagnose.manager.MessageWhat;
import cc.ufinity.networkdiagnose.manager.Task;
import cc.ufinity.networkdiagnose.view.R;

public class OtherTestWidgetProxy extends GeneralTestWidget {

    private Activity ctx;
    private final Handler handler; 
    private static String TAG = "rssiTest"; 
    private static String TAG2 = "snrTest"; 
    private Task task;
	private int testFlag = 0; 
	private int testFlag2 = 0; 
    public OtherTestWidgetProxy(Activity context) {
        super(context);
        this.ctx = context;
        inflate(context, R.layout.webauth_test_widget_proxy, this);
         
 
        handler = new Handler() {
            public void handleMessage(Message msg) {
                switch (msg.what) {
                case MessageWhat.DO_NEXT_TEST:
                    showNextText();
                    break;                      
                }
            }
        }; 
        task = (Task)ctx.getIntent().getSerializableExtra(TAG_REFER_TASK);
        int frequency = task.testCount;
        task.snr = String.valueOf(task.scanResult.level*(-1));
        mSendBroadcast(ctx,TAG2);
        doNextTest();
        task.rssi =String.valueOf( task.scanResult.level);
        mSendBroadcast(ctx,TAG);
        ctx.getIntent().putExtra(TAG_REFER_TASK, task);
        showNextText() ;
    } 
    private void showNextText() {
        if(task.taskType.equals(Task.TASK_TYPE_Y)){
            TaskResult stw = new TaskResult(ctx);
           // ctx.setContentView(stw);
        }else{
            TaskResult tr = new TaskResult(ctx);
           // ctx.setContentView(tr);
        }
        
    }
    public void mSendBroadcast(Activity activity,String flag) {
		Intent intent = new Intent();
		intent.setAction("doNext");
		if(flag.equals("rssiTest"))
			intent.putExtra("testIndex",flag+String.valueOf(testFlag++));
		else if (flag.equals("snrTest"))
			intent.putExtra("testIndex",flag+String.valueOf(testFlag2++));
		activity.sendBroadcast(intent);
	} public void mSendBroadcast(Activity activity) {
		Intent intent = new Intent();
		intent.setAction("doNext");
		intent.putExtra("testIndex",TAG );
		activity.sendBroadcast(intent);
	}
    private void doNextTest() {
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
               // sendMsg(MessageWhat.DO_NEXT_TEST, handler);
            }
        };
        Timer t = new Timer();
        t.schedule(timerTask, TASK_PERFORM_INTERVAL); 
    }
	/*public static int getTestFlag() {
		return testFlag;
	}
	public static void setTestFlag(int testFlag) {
		OtherTestWidgetProxy.testFlag = testFlag;
	}
	public static int getTestFlag2() {
		return testFlag2;
	}
	public static void setTestFlag2(int testFlag2) {
		OtherTestWidgetProxy.testFlag2 = testFlag2;
	}*/
  
}
